Online-Academy
Look, Read, Understand, Apply

Pandas - Dataframe

import pandas as pd
if __name__ == "__main__":
    df = pd.read_csv("records_i.csv")
    print(df.describe())
    print("Mean Age: ",df["Age"].mean()) #get mean of age attribute
    print("Median Age: ",df["Age"].median()) #get median age
    print("Most Frequent Age: ", df["Age"].mode()) # get most frequent age
    print("Min Age: ",df["Age"].min())  #get minimum age
    print("Max Age: ",df["Age"].max())  #get maximum age
    print("Number of Records: ",len(df))    #get number of records
    print("Age ins: ",df.loc[df["Age"].isin([15,21,12])])  # check if record with age given in the list exist
    print("Name: ",df["Name"]," Age: ",df["Age"])  #display name and age. 
    print("Second person: ",df.loc[1,"Name"])  #display name of second record
    print(df.to_string())  #convert dataframe to string
    print(df.head())  #display first five records
    print(df.tail()) # dispaly last five records
    print(df.shape)   #display dimensions
    print(df.loc[[0,1,2,5]]) #will display 1, 2,3, and 6th rows
    print("0: ",df.loc[1])  #will display specified record in tabular form
    print("1: ",df.iloc[1])
    df.iloc[0] = {"SN":100, "Name":"Dharmendra","Age":33,"Income":3000} # update record in data frame
    print("0:",df.iloc[0])
    df.loc[2,'age'] = 34   # update age of third record
    print(df)
    print(df.loc[df.age == 34])  #print record with age 34